import { render } from '@testing-library/react'
import { BrowserRouter } from 'react-router-dom'

// 为需要路由的组件提供包装
export const renderWithRouter = (ui, { route = '/' } = {}) => {
  window.history.pushState({}, 'Test page', route)
  return render(ui, { wrapper: BrowserRouter })
}

// 为需要特定上下文的组件提供包装
export const renderWithProviders = (ui, { providers = [] } = {}) => {
  const Wrapper = ({ children }) => {
    return providers.reduce(
      (acc, Provider) => <Provider>{acc}</Provider>,
      children
    )
  }
  return render(ui, { wrapper: Wrapper })
}